package educar.controllers;

import java.sql.SQLException;

import educar.db.JPA;
import educar.gui.DatosActView;
import educar.gui.DatosView;
import educar.gui.DocenteActView;
import educar.gui.DocenteCorreccionView;
import educar.gui.IView;
import educar.gui.LoginView;
import educar.models.Actividad;
import educar.models.Correccion;
import educar.models.Docente;
import educar.models.Session;
import educar.models.User;

public class NotaController implements IController {
       DocenteActView dact;
       private DocenteCorreccionView docC;
       private JPA jpa=new JPA();
       private Correccion correc;
       Integer nota=null;
       String dni;
       String nomAct;
       String idAct;
       String user;
       String id_solucion;       
       
        public void process(String model){
        	nota=Integer.parseInt(docC.getNota());
        	// FALTA CARGAR ACA:
        	user=Session.getCurrentUser().getUsername();
        	try {
				dni= (jpa.getConsulta("users", "dni", "username='"+ user+"'"))[0];
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        	nomAct= docC.getActividad(); 
        	
        	 try {
 				idAct= (jpa.getConsulta("actividad", "id", "nombre='"+nomAct+"'"))[0];
 			} catch (SQLException e) {
 				// TODO Auto-generated catch block
 				e.printStackTrace();
 			}
 			
 			 try {
  				id_solucion= (jpa.getConsulta("solucion", "id", "id_act='"+idAct+"'"))[0];
  			} catch (SQLException e) {
  				// TODO Auto-generated catch block
  				e.printStackTrace();
  			}
  			/* try {
  				dniAlum= (jpa.getConsulta("solucion", "dni", "id_act='"+idAct+"'"))[0];
  			} catch (SQLException e) {
  				// TODO Auto-generated catch block
  				e.printStackTrace();
  			}*/
  		    correc = new Correccion(nota,dni,Integer.parseInt(idAct),Integer.parseInt(id_solucion));
        	correc.save();
        
        }

        @Override
        public void setView(IView docC) {
                this.docC = (DocenteCorreccionView) docC;   
        }       
}